
const MingSericalRunCode= require("./MingSericalTimeOutRunCode.js");

sendCallback=()=>{};

class MingSerialClient {
    constructor(com) {
        this.mingSericalRunCode=new MingSericalRunCode({
            com:com,
            brand:115200,
            isNodeExecute:false,
            //接收单片机的请求
            async messageEvent(m){
                if(sendCallback!=null){
                    sendCallback(m);
                    sendCallback=null;
                }
            }});
    }
   async send(param){
        let that=this;
        return new Promise(
            async function (reslove) {
                await that.mingSericalRunCode.usartSend(param);
                sendCallback=(v)=>{
                    reslove(v);
                }
                setTimeout(()=>{
                    reslove(0);
                },2000)
            }
        )
    }
}
module.exports = MingSerialClient;